package com.hf.eagle.web.struts;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.hf.eagle.domain.Accessory;
import com.hf.eagle.domain.NewsInfo;
import com.hf.eagle.domain.ProductInfo;
import com.hf.eagle.domain.SaleGrid;
import com.hf.eagle.domain.SiteLink;
import com.hf.eagle.web.base.BaseAction;
import com.hf.eagle.web.base.SysConstant;

public class IndexAction extends BaseAction {

	public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		return this.index(mapping, form, request, response);
	}

	public ActionForward index(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// 促销动态 取一页4个
		NewsInfo newsInfo = new NewsInfo();
		newsInfo.setIs_del(0);
		newsInfo.setInfo_state(SysConstant.PUBLISH);
		newsInfo.setMod_id((long) 2902);

		newsInfo.getRow().setFirst(0);
		newsInfo.getRow().setCount(5);

		List<NewsInfo> list2902 = super.getFacade().getNewsInfoService().getNewsInfoPaginatedList(newsInfo);
		if (null != list2902 && list2902.size() > 0) {
			for (NewsInfo newsInfo2 : list2902) {
				if (null != newsInfo2) {
					Accessory acce = new Accessory();
					acce.setFile_level(SysConstant.SUB_IMG);
					acce.getMap().put("mod_id", "2902");
					acce.getMap().put("record_id", newsInfo2.getId());
					acce = super.getFacade().getAccessoryService().getAccessory(acce);
					newsInfo2.setAccessory(acce);
				}
			}
		}
		request.setAttribute("NewsInfo2902", list2902);

		// 最新消息 取一页7个
		newsInfo.setMod_id((long) 2901);
		newsInfo.getRow().setFirst(0);
		newsInfo.getRow().setCount(7);

		List<NewsInfo> list2901 = super.getFacade().getNewsInfoService().getNewsInfoPaginatedList(newsInfo);
		request.setAttribute("NewsInfo2901", list2901);

		// 销售网点 取一页4个
		SaleGrid sg = new SaleGrid();
		sg.setIs_del(0);
		sg.setIs_shop(1);

		sg.getRow().setFirst(0);
		sg.getRow().setCount(4);
		List<SaleGrid> saleGrids = getFacade().getSaleGridService().getSaleGridPaginatedList(sg);
		if (null != saleGrids && saleGrids.size() > 0) {
			for (SaleGrid saleGrid : saleGrids) {
				if (null != saleGrid) {
					Accessory acce = new Accessory();
					acce.setFile_level(SysConstant.SUB_IMG);
					acce.getMap().put("mod_id", "2400");
					acce.getMap().put("record_id", saleGrid.getGrid_id());
					acce = super.getFacade().getAccessoryService().getAccessory(acce);
					saleGrid.setAccessory(acce);
				}
			}
		}
		request.setAttribute("saleGrids", saleGrids);

		// 广告宣传 取一页4个
		SiteLink advertisingSiteLink = new SiteLink();
		advertisingSiteLink.setIs_del(0);
		advertisingSiteLink.setMod_id((long) 2810);

		advertisingSiteLink.getRow().setFirst(0);
		advertisingSiteLink.getRow().setCount(4);
		List<SiteLink> advertisingSiteLinks = getFacade().getSiteLinkService().getSiteLinkPaginatedList(
				advertisingSiteLink);
		if (null != advertisingSiteLinks && advertisingSiteLinks.size() > 0) {
			for (SiteLink siteLink : advertisingSiteLinks) {
				if (null != siteLink) {
					Accessory acce = new Accessory();
					acce.setFile_level(SysConstant.SUB_IMG);
					acce.getMap().put("mod_id", "2810");
					acce.getMap().put("record_id", siteLink.getId());
					acce = super.getFacade().getAccessoryService().getAccessory(acce);
					siteLink.setAccessory(acce);
				}
			}
		}
		request.setAttribute("advertisingSiteLinks", advertisingSiteLinks);

		// 推荐产品 取完//测试网速
		ProductInfo productInfo = new ProductInfo();
		productInfo.setIs_del(0);
		productInfo.setIs_recommend(1);
		productInfo.getRow().setFirst(0);
		productInfo.getRow().setCount(20);
		List<ProductInfo> productInfoList = super.getFacade().getProductInfoService().getProductInfoPaginatedList(
				productInfo);
		if (null != productInfoList && productInfoList.size() > 0) {
			for (ProductInfo product_info : productInfoList) {
				Accessory acce = new Accessory();
				acce.setFile_level(SysConstant.SUB_IMG);
				acce.getMap().put("mod_id", "3200");
				acce.getMap().put("record_id", product_info.getProduct_id());
				acce = super.getFacade().getAccessoryService().getAccessory(acce);
				product_info.setAccessory(acce);
			}
		}
		request.setAttribute("productInfoList", productInfoList);

		// 顶部动态广告,取5个
		NewsInfo dynamicAd = new NewsInfo();
		dynamicAd.setMod_id(4400l);
		dynamicAd.setIs_del(0);
		dynamicAd.setInfo_state(SysConstant.PUBLISH);
		dynamicAd.getRow().setFirst(0);
		dynamicAd.getRow().setCount(5);
		List<NewsInfo> dynamicAdList = super.getFacade().getNewsInfoService().getNewsInfoPaginatedList(dynamicAd);
		if (null != dynamicAdList && dynamicAdList.size() > 0) {
			for (NewsInfo dynamic_ad : dynamicAdList) {
				Accessory acce = new Accessory();
				acce.setFile_level(SysConstant.MAIN_IMG);
				acce.getMap().put("mod_id", "4400");
				acce.getMap().put("record_id", dynamic_ad.getId());
				acce = super.getFacade().getAccessoryService().getAccessory(acce);
				dynamic_ad.setAccessory(acce);
			}
		}
		request.setAttribute("dynamicAdList", dynamicAdList);

		// 友情链接
		// SiteLink siteLink = new SiteLink();
		// siteLink.setIs_del(0);
		// siteLink.setMod_id((long) 4200);
		// List<SiteLink> siteLinks = getFacade().getSiteLinkService().getSiteLinkList(siteLink);
		// request.setAttribute("siteLinks", siteLinks);

		return mapping.findForward("success");
	}
}